package com.vidmt.api.modules.sys.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;

import com.vidmt.api.modules.sys.auth.AuthFactory;

public class MyCredentialMather implements CredentialsMatcher {

	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
		String tokenStr = null, infoStr = null;

		if (token instanceof MyWebToken) {
			tokenStr = new String((char[]) token.getCredentials());
			infoStr = (String) info.getCredentials();
		} else if (token instanceof MyApiToken) {
			tokenStr = (String) token.getCredentials();
			infoStr = (String) info.getCredentials();
		}
		return AuthFactory.authenticate(tokenStr, infoStr);
	}

}
